package com.kongjs.application.model.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.time.LocalDateTime;
import java.util.Objects;

@Getter
@Setter
@ToString
@MappedSuperclass
public abstract class Base {

    @TableField(value = "tenant_id", fill = FieldFill.INSERT, insertStrategy = FieldStrategy.NOT_NULL)
    private Long tenantId;

    @TableField(value = "enabled", fill = FieldFill.INSERT, insertStrategy = FieldStrategy.NOT_NULL)
    private Integer enabled;

    @TableField(value = "deleted", fill = FieldFill.INSERT, insertStrategy = FieldStrategy.NOT_NULL)
    private Integer deleted;

    @TableField(value = "create_date", fill = FieldFill.INSERT, insertStrategy = FieldStrategy.NOT_NULL)
    private LocalDateTime createDate;

    @TableField(value = "update_date", fill = FieldFill.INSERT_UPDATE, insertStrategy = FieldStrategy.NOT_NULL, updateStrategy = FieldStrategy.NOT_NULL)
    private LocalDateTime updateDate;

    @TableField(value = "create_user_id", fill = FieldFill.INSERT, insertStrategy = FieldStrategy.NOT_NULL)
    private Long createUserId;

    @TableField(value = "update_user_id", fill = FieldFill.INSERT_UPDATE, insertStrategy = FieldStrategy.NOT_NULL, updateStrategy = FieldStrategy.NOT_NULL)
    private Long updateUserId;

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Base base)) return false;
        return Objects.equals(tenantId, base.tenantId) && Objects.equals(enabled, base.enabled) && Objects.equals(deleted, base.deleted) && Objects.equals(createDate, base.createDate) && Objects.equals(updateDate, base.updateDate) && Objects.equals(createUserId, base.createUserId) && Objects.equals(updateUserId, base.updateUserId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(tenantId, enabled, deleted, createDate, updateDate, createUserId, updateUserId);
    }
}
